package com.wfx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wfx.entity.Result;
import com.wfx.entity.ViewCatTpl;
import com.wfx.entity.WxbGoodsCat;
import com.wfx.mapper.WxbGoodsCatMapper;
import com.wfx.service.IWxbGoodsCatService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 商品类目 服务实现类
 * </p>
 *
 * @author zhu
 * @since 2021-01-22
 */
@Service
public class WxbGoodsCatServiceImpl extends ServiceImpl<WxbGoodsCatMapper, WxbGoodsCat> implements IWxbGoodsCatService {
    @Autowired(required = false)
    private WxbGoodsCatMapper wxbGoodsCatMapper;
    @Override
    public Result addOrUpdate(WxbGoodsCat wxbGoodsCat) {
        if (wxbGoodsCat.getId()==null){
            int insert1 = wxbGoodsCatMapper.insert(wxbGoodsCat);
            return new Result(insert1==1?true:false,insert1==1?"添加成功":"添加失败");
        }else {
            QueryWrapper<WxbGoodsCat> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("id",wxbGoodsCat.getId());
            int update = wxbGoodsCatMapper.update(wxbGoodsCat, queryWrapper);

            return new Result(update==1?true:false,update==1?"修改成功":"修改失败");
        }
    }
}
